//
//  BankCardManageViewController.m
//  NiuBanJinGold
//
//  Created by zf on 15/10/12.
//  Copyright © 2015年 zzjr. All rights reserved.
//

#import "BankCardManageViewController.h"

@interface BankCardManageViewController ()
@property (nonatomic , strong) NSMutableArray *mutableArray_data;
@property (nonatomic ,strong) NSDictionary *dic_bank;
@end

@implementation BankCardManageViewController

-(void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.mutableArray_data = [NSMutableArray array];
    [self getDataFromNet];
}

-(void)getDataFromNet {
    
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *dic_safe = @{@"userId" : GETCURRENTUSERINOBYPRAMETERES(user_userId) , @"token" : GETCURRENTUSERINOBYPRAMETERES(user_userToken)};
    
    [[NETWorkingUtil sharedNETWorking] zzjrMore_safeCenterByParmeteres:dic_safe transferResultUsingBlock:^(id parsedData, NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.view animated:YES];
        if (!error) {
            
            if ([parsedData[@"status"] integerValue ] == 0) {
                NSDictionary *dic_result = parsedData[@"result"];
                if ([dic_result[@"authentication"]integerValue] == 0) {
                    
                 
                }else {
                    
                  
                   NSString * bankCardNumber = dic_result[@"bankCardNumber"];
                    NSString * bankName = dic_result[@"bankName"];
                    if (bankName.length != 0 && bankCardNumber.length != 0) {
                        
                        UILabel *labelBankCardNumber = (UILabel *)[self.view viewWithTag:201];
                        labelBankCardNumber.text = bankCardNumber;
                        
                        UIImageView *imageView_bank = (UIImageView *)[self.view viewWithTag:404];
                        imageView_bank.image = [UIImage imageNamed:self.dic_bank[bankName]];
                        
//                        [self.mutableArray_data removeLastObject];
//                        [self.mutableArray_data addObject:bankName];
//                        [self.mutableArray_data addObject:bankCardNumber];
//                        [self setValueForLabelText];
                    }
                  
                }
                
            }else{
                
                [UsefulUtil showAlertView:parsedData[@"msg"]];
            }
        }else {
            
            [UsefulUtil showAlertView:@"遇到网络问题,请稍后重试!"];
        }
        
    }];
    

}

-(void)setValueForLabelText {
    NSLog(@"%@" ,self.mutableArray_data[0] );
    UILabel *labelBankCardNumber = (UILabel *)[self.view viewWithTag:201];
    labelBankCardNumber.text = [NSString stringWithFormat:@"%@" ,self.mutableArray_data[1]];
    
    UIImageView *imageView_bank = (UIImageView *)[self.view viewWithTag:404];
    imageView_bank.image = [UIImage imageNamed:self.dic_bank[self.mutableArray_data[0]]];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"银行卡管理";
    
    self.dic_bank = @{@"中信银行" : @"zhongxin.png" , @"中国银行" : @"zhongguo.png" , @"招商银行" : @"zhaoshang.png" , @"兴业银行" : @"xingye.png" , @"上海浦东发展银行" : @"pufa.png" , @"平安银行" : @"pingan.png" , @"中国农业银行" : @"nongye.png" , @"中国民生银行" : @"mingsheng.png" , @"交通银行" : @"jiaotong.png" , @"中国建设银行" : @"jianshe.png" , @"广东发展银行" : @"guangfa.png" , @"中国光大银行" : @"guangda.png" , @"中国工商银行" : @"gongshang.png" , @"华夏银行" : @"huaxia.png" , @"中国邮政储蓄银行" : @"youzheng.png"};
    
    //银行卡图片
    UIImageView *imageView_bank = [[UIImageView alloc]init];
    imageView_bank.tag = 404;
   imageView_bank.frame = CGRectMake(MULTIPLYWIDTH(54.0), MULTIPLYHEIGHT(24.0), SCREEN_WIDTH - MULTIPLYWIDTH(108.0), MULTIPLYHEIGHT(130.0));
    imageView_bank.image = [UIImage imageNamed:@"huaxia.png"];
    [self.view addSubview:imageView_bank];
    
    //提醒图片
    UIImageView *img_safe = [[UIImageView alloc]init];
    img_safe.frame = CGRectMake(MULTIPLYWIDTH(75.0), CGRectGetMaxY(imageView_bank.frame) + MULTIPLYHEIGHT(25.0), MULTIPLYWIDTH(11.0), MULTIPLYHEIGHT(13.0));
    img_safe.image = [UIImage imageNamed:@"safe.png"];
    [self.view addSubview:img_safe];
    UILabel *label_text = [[UILabel alloc]init];
    label_text.text = @"为了资金安全,本平台仅支持绑定一张银行卡";
    label_text.frame = CGRectMake(CGRectGetMaxX(img_safe.frame) + MULTIPLYWIDTH(5), CGRectGetMaxY(imageView_bank.frame) + MULTIPLYHEIGHT(25.0), MULTIPLYWIDTH(215), MULTIPLYHEIGHT(13));
    label_text.adjustsFontSizeToFitWidth = YES;
    label_text.font = [UIFont systemFontOfSize:11.0];
    label_text.textColor = [UsefulUtil colorWithHexString:@"#5f5f61"];
    [self.view addSubview:label_text];
    
    
    //银行卡号
    UILabel *label_bankCardNumber = [[UILabel alloc]init];
    label_bankCardNumber.frame = CGRectMake(CGRectGetWidth(imageView_bank.frame) * 200 / 530, MULTIPLYHEIGHT(197.0 / 2), MULTIPLYWIDTH(160.0), MULTIPLYHEIGHT(17.0));
    label_bankCardNumber.tag = 201;
    label_bankCardNumber.font = [UIFont systemFontOfSize:15.0];
    label_bankCardNumber.text = @"4555";
    label_bankCardNumber.textColor = [UsefulUtil colorWithHexString:@"#434343"];
    label_bankCardNumber.textAlignment = NSTextAlignmentCenter;
    [imageView_bank addSubview:label_bankCardNumber];
    
    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeGestureAction)];
    [self.view addGestureRecognizer:swipeGesture];
    
}

#pragma mark -swipeGestureAction
-(void)swipeGestureAction{
    [self.navigationController popViewControllerAnimated:YES];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
